package com.ruicar.afs.cloud.basic.common.utils;

import cn.hutool.core.date.DateUtil;
import com.ruicar.afs.cloud.basic.common.entity.BasicMainInfo;
import com.ruicar.afs.cloud.basic.mq.sender.BasicSender;
import com.ruicar.afs.cloud.basic.proceeds.mq.sender.FinanceSender;
import com.ruicar.afs.cloud.common.modules.dto.mq.loan.contractdto.LoanActivateReceiveNoticeDTO;
import com.ruicar.afs.cloud.common.mq.rabbit.message.AfsTransEntity;
import com.ruicar.afs.cloud.common.mq.rabbit.message.MqTransCode;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @author: Lee
 * @date: 2020/5/11 19:39
 * @description: mq发送统一管理
 */
@AllArgsConstructor
@Service
public class MqSendUtils {

    private final BasicSender basicSender;
    private final FinanceSender financeSender;

    /**
     * 合同关闭、激活成功、激活失败、合同取消，mq通知案件
     * 跑批工程里面也有个同样的mq，合同关闭！同一个通道 ContractCloseBathRunner.class  handleSmsAndMq
     * @param dto
     */
    public void contractStatusChange(LoanActivateReceiveNoticeDTO dto){
        AfsTransEntity<LoanActivateReceiveNoticeDTO> afsTransEntity = new AfsTransEntity<>();
        afsTransEntity.setData(dto);
        afsTransEntity.setTransCode(MqTransCode.AFS_CONTRACT_BASIC_CASE_CTM_ACTIVATION_STATUS);
        basicSender.sendContractBasicToCtmCase(afsTransEntity);
    }


    /**
     * 合同激活成功通知进件系统
     */
    public void sendApply(BasicMainInfo mainInfo){
        BasicMainInfo info = new BasicMainInfo();
        BeanUtils.copyProperties(mainInfo, info);
        info.setStartDate(DateUtil.date());
        AfsTransEntity<BasicMainInfo> sendEntity = new AfsTransEntity<>();
        sendEntity.setData(info);
        sendEntity.setTransCode(MqTransCode.CONTRACT_BASIC_POS_APPLY);
        financeSender.sendContractActiveToApply(sendEntity);
    }
}
